package data_structures_and_algorithms.list_node;

import common.ListNode;

import javax.swing.text.html.parser.TagElement;

/**
 * @ClassName Code_0019_removeNthFromEnd
 * @Description: TODO
 * @Author: myl
 * @create_time: 2022/10/28 00:37
 */
public class Code_0019_removeNthFromEnd {

    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode target = new ListNode(0), pre = target;
        pre.next = head;
        ListNode cur = pre;
        while (n > 0){
            cur = cur.next;
            n--;
        }

        while (cur.next != null){
            pre = pre.next;
            cur = cur.next;
        }
        cur.next = cur.next.next;
        return target.next;
    }
}
